package com.yunji.cabinet.service.impl;

import com.yunji.cabinet.bo.CabinetCellListQueryBO;
import com.yunji.cabinet.bo.CabinetCellSelectQueryBO;
import com.yunji.cabinet.bo.CabinetCellUpdateBO;
import com.yunji.cabinet.bo.FillCargoBO;
import com.yunji.cabinet.dao.ICabinetCellDao;
import com.yunji.cabinet.domain.ContainerCell;
import com.yunji.cabinet.service.ICabinetCellService;
import com.yunji.cabinet.vo.CellProductCountVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @version 1.0
 * @Project: yunji-coffee
 * @Package com.yunji.cabinet.service.impl
 * @FileName CabinetCellServiceImpl.java
 * @Copyright Copyright © 2024 云集互联. All Rights Reserved
 * Company		com
 * @CreateTime 2024-04-08 20:55:37
 * @Description 货柜格子接口实现
 * @Modification Author                    History Time			Version				Description
 * --------------------------------------------------------------------------------
 * HuaAo				2024-04-08 20:55:37		1.0					1.0 Version
 * @since JDK 1.8.0_202
 */
@Service
public class CabinetCellServiceImpl implements ICabinetCellService {

    @Resource
    private ICabinetCellDao cabinetCellDao;


    /**
     * @return boolean 新增结果
     * @Title create
     * @Desc 新增货柜格子
     * @Date 2024-04-09 19:49:14
     * @Param cell 格子信息
     */
    @Override
    public boolean create(ContainerCell cell) {
        return cabinetCellDao.save(cell);
    }


    @Override
    public boolean create(List<ContainerCell> cells) {
        return cabinetCellDao.saveBatch(cells);
    }


    /**
     * @return boolean 修改结果
     * @Title update
     * @Desc 修改货柜格子
     * @Date 2024-04-09 19:49:14
     * @Param cell 格子信息
     */
    @Override
    public boolean update(CabinetCellUpdateBO bo) {
        return cabinetCellDao.update(bo);
    }

    /**
     * @return boolean 删除结果
     * @Title delete
     * @Desc 删除格子信息
     * @Date 2024-04-09 19:48:32
     * @Param ids 过滤条件
     */
    @Override
    public boolean deleteByContainerIds(Long... ids) {
        return cabinetCellDao.deleteByContainerIds(ids);
    }

    @Override
    public List<ContainerCell> searchCountCell(CabinetCellListQueryBO bo) {
        return cabinetCellDao.searchCountCell(bo);
    }

    /**
     * @return int 商品数量
     * @Title getRemainProduct
     * @Desc 获取剩下商品数量
     * @Date 2024-04-12 18:11:32
     * @Param containerId 货柜ID
     */
    @Override
    public int getRemainProduct(Long containerId) {
        return cabinetCellDao.getRemainProduct(containerId);
    }

    @Override
    public ContainerCell select(CabinetCellSelectQueryBO bo) {
        return cabinetCellDao.select(bo);
    }

    @Override
    public List<ContainerCell> searchByContainerId(Long containerId) {
        return cabinetCellDao.searchByContainerId(containerId);
    }

    @Override
    public List<FillCargoBO> searchFillCargoCells() {
        return cabinetCellDao.searchFillCargoCells(LocalDateTime.now().minusDays(3L));
    }

    @Override
    public List<CellProductCountVO> countCellProduct(Long belongId) {
        return cabinetCellDao.countCellProduct(belongId);
    }

    @Override
    public boolean addProduct(Long cabinetId, Integer... nums) {
        return cabinetCellDao.addProduct(cabinetId, nums);
    }

    @Override
    public List<ContainerCell> search(CabinetCellListQueryBO bo) {
        return cabinetCellDao.search(bo);
    }

    @Override
    public void updateBatch(List<ContainerCell> updateList) {
        cabinetCellDao.updateBatchById(updateList);
    }

    @Override
    public void saveBatch(List<ContainerCell> createList) {
        cabinetCellDao.saveBatch(createList);
    }

    @Override
    public List<ContainerCell> getCellListCache(Long containerId) {
        return cabinetCellDao.listByContainerId(containerId);
    }

}
